<template>
  <div>
    <div class="app-container">
      <Header title="修改密码" class="app-container" />

      <!-- <div>&nbsp;&nbsp;</div> -->
      <!-- <div>&nbsp;&nbsp;</div>
      <div>&nbsp;&nbsp;</div> -->
      <mt-field
        v-model="form.username"
        label="用户名"
        placeholder="请输入用户名"
      />

      <Password
        v-model="form.password0"
        label="旧密码"
        placeholder="请输入旧密码"
      />

      <Password
        v-model="form.password"
        label="新密码"
        placeholder="请输入新密码"
      />

      <Password
        v-model="form.password2"
        label="确认密码"
        placeholder="再次输入新密码"
      />

      <mt-button type="primary" @click.native="handleChange">
        确认修改密码
      </mt-button>
      <div>
        <!-- {{ partner }} -->
      </div>
    </div>
  </div>
</template>

<script>
import Header from '@/components3/Header'
import Password from '@/components3/Field/Password'

export default {
  name: 'MeConsultant',
  components: { Header, Password },
  directives: {},
  filters: {},
  // mixins: [],
  props: {},

  data() {
    return {
      form: {
        username: '',
        password0: '',
        password: '',
        password2: ''
      }
    }
  },
  computed: {},
  async created() {
    //
  },

  methods: {
    handleChange() {
      console.log('xxx, click handleChangePsw,')
      if (!this.form.username) {
        this.$message({
          message: '请输入用户名',
          type: 'error'
        })
      } else if (!this.form.password0) {
        this.$message({
          message: '请输入旧密码',
          type: 'error'
        })
      } else if (!this.form.password) {
        this.$message({
          message: '请输入新密码',
          type: 'error'
        })
      } else if (this.form.password.length < 6) {
        this.$message({
          message: '新密码至少6位',
          type: 'error'
        })
      } else if (this.form.password !== this.form.password2) {
        this.$message({
          message: '两次输入的新密码不一致',
          type: 'error'
        })
      } else {
        //
        const ret = this.$store.dispatch('user/changePassword', {
          oldPsw: this.form.password0,
          newPsw: this.form.password
        })
        // console.log('xxx,checkPsw ', res)
        ret.then(res => {
          console.log('xxx,checkPsw ', res)
          if (res) {
            this.$store.dispatch('appView/selectHome', 'home')
            this.$router.push('/app/login')
          }
        })
      }
    }
  }
}
</script>

<style type="text/css"></style>
